<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/common/common.jsp" %>
<html>
<head>
    <%@ include file="/common/head.jsp" %>
    <style type="text/css">
        .ui-button .ui-button-text {
            font-size: 1.0em;
            vertical-align: center;
            line-height: 1.0em;
            padding-top: 0.5em;
        }

        BUTTON.Browser {
            BORDER-RIGHT: medium none;
            BORDER-TOP: medium none;
            BACKGROUND-IMAGE: url(/images/face/toolbar_searching.gif);
            OVERFLOW: hidden;
            BORDER-LEFT: medium none;
            WIDTH: 16px;
            CURSOR: hand;
            BORDER-BOTTOM: medium none;
            BACKGROUND-REPEAT: no-repeat;
            HEIGHT: 16px;
            BACKGROUND-COLOR: transparent
        }
    </style>
    <title>customerInfo.jsp</title>
    <%
	    String reportid = StringUtil.null2String(request.getParameter("reportid"),"1");
        int pageSize = 20;
        String allsub = StringUtil.null2String(request.getParameter("allsub"));
        String humanid ="";
        humanid = StringUtil.null2String(Env.getRemoteUser().getCurrentuserid());
    %>

    <script type="text/javascript">
        var store;
        var baseParams = {};
        var resourceid;
        Ext.onReady(function () {
            store = new Ext.data.JsonStore({
                url:'/reportdata.do?&isnew=1&action=search&reportid=<%=reportid%>&isjson=1&pagesize=20',
                root:'result',
                totalProperty:'totalCount',
                fields:['processid','objno','objname','orgid','postid','tel2','email','hrstatus','seclevel'],
                remoteSort:true
            });
            var sm = new Ext.grid.CheckboxSelectionModel();
            var cm = new Ext.grid.ColumnModel([
                    {header:'姓名',dataIndex:'objname',width:83,sortable:true},
                    {header:'部门',dataIndex:'orgid',width:83,sortable:true}
            ]);
            cm.defaultSortable = true;
            var grid = new Ext.grid.GridPanel({
				<%if(!StringUtil.isEmpty(allsub)){%>
                title:'下属信息：  <button  class=Browser type=button onclick="getBrowser(\'concs_human_orgids_value\',\'concs_human_orgidsspan\',\'6\',\'/hrm/org/orgview.jsp?id=\',\'0\');"></button><input type="hidden" id="concs_human_orgids_value" name="concs_human_orgids_value" value=""><span id="concs_human_orgidsspan" name="concs_human_orgidsspan" ></span><input  type="checkbox" name="concs_human_orgid_checkbox" value="1" onclick="reloadhuman()">',<%}%>
                region:'west',
                store:store,
                cm:cm,
                trackMouseOver:false,
                sm:sm,
                split:true,
                width:250,
                collapsible:true,
                collapseMode:'mini',
                viewConfig:{
                    forceFit:true,
                    enableRowBody:true,
                    sortAscText:'升序',
                    sortDescText:'降序',
                    columnsText:'列定义'
                },
                bbar:new Ext.PagingToolbar({
                    pageSize: 20,
                    store:store,
                    displayInfo:false,
                    beforePageText:'第',
                    afterPageText:'页\/{0}',
                    firstText:'第一页',
                    prevText:'上页',
                    nextText:'下页',
                    lastText:'最后页',
                    displayMsg:'显示 {0} - {1}条记录 \/ {2}',
                    emptyMsg:'没有结果返回'
                })
            });

        <% if(StringUtil.isEmpty(allsub)){
            String posts=Env.getRemoteUser().getPostids();
            String humansqlwhere="manager='"+ humanid+"'";
            if(!StringUtil.isEmpty(posts)){
                posts="'"+posts.replaceAll(",","','")+"'";
            }
            humansqlwhere ="manager='"+ humanid+"' or ("+"exists (select 'X' from (select postid from cs_postrelationship where parentid in("+posts+") ) tmp where cs_human.postids like "+SqlUtil.concat("'%'","tmp.postid","'%'")+"  )"+")";
%>
            store.baseParams.sqlwhere = "<%=StringUtil.getEncodeStr(humansqlwhere)%>";
            <%}%>

            <% if(!StringUtil.isEmpty(allsub)){
                    String postids=Env.getRemoteUser().getPostids();
                    String humansqlwhere="manager='"+ humanid+"'";
                    PostService postService=Env.getBean("postService");
                    String posts="";
                    String[] post_arr= StringUtil.string2Array(postids,",");
                    for(String temp:post_arr){
                    List<String> subids=postService.getAllSubPostidList(temp, null, "1", true);
                        for (String subid : subids) {
                            posts += "," + subid;
                        }
                    }
                    posts= StringUtil.formatMutiIDs(posts);
                    if(!StringUtil.isEmpty(posts)){
                        humansqlwhere ="("+"exists (select 'X' from (select postid from cs_postrelationship where parentid in("+posts+") ) tmp where cs_human.postids like "+
                        SqlUtil.concat("'%'","tmp.postid","'%'")+"  )"+")";
                    }
            %>
            store.baseParams.sqlwhere = "<%=StringUtil.getEncodeStr(humansqlwhere)%>";
            <%}%>
            store.load({params:{start:0, limit:<%=pageSize%>}});

            sm.on('rowselect', function (selMdl, rowIndex, rec) {
                    if(rec != null){
                    var humanid = rec.get('processid');//日程管理
                    //alert(humanid);
                    baseParams.humanid = humanid;
                    baseParams.resourceid = humanid;
                    var suoyoukehu_url = '/reportdata.do?action=search&isnew=1&reportid=402881ef3cfb57d2013cfb81789a007f&conut_customerinfo_managerid_value='+humanid;
                    rightframe.location = suoyoukehu_url;
                }
            });

                var viewport = new Ext.Viewport({
                layout: 'border',
                items: [
                    grid,
                    {
                        region: 'center',
                        xtype: 'iframepanel',
                        frameConfig: {
                            id: 'rightframe',
                            name: 'rightframe',
                            frameborder: 0,
                            eventsFollowFrameLinks: false
                        },
                        autoScroll: true
                    }]
            });
        });

        function getBrowser(inputname, inputspan, browserid, viewurl, isneed) {

            var idsin = document.getElementsByName(inputname)[0].value;
            var id;
            try {
                var url = '/browser/browser.jsp?id=' + browserid + '&idsin=' + idsin;
                if (idsin.length > 900) {   //当idsin过长时，ie的url不支持过长的地址
                    url = '/browser/browser.jsp?id=' + browserid;
                }
                id = showDialog(url);
            } catch (e) {
                return
            }
            if (id != null) {

                if (id[0] != '0') {
                    document.getElementById(inputname).value = id[0];
                    document.getElementById(inputspan).innerHTML = id[1];

                } else {
                    document.getElementById(inputname).value = '';
                    if (isneed == '0')
                        document.getElementById(inputspan).innerHTML = '';
                    else
                        document.getElementById(inputspan).innerHTML = '<img src=/images/base/checkinput.gif>';

                }
            }
            store.load({params:{concs_human_orgid_value:document.getElementById('concs_human_orgids_value').value, concs_human_orgid_checkbox:0+document.getElementById('concs_human_orgid_checkbox').checked,start:0, limit:<%=pageSize%>}});
        }

        function reloadhuman(){
            store.load({params:{concs_human_orgid_value:document.getElementById('concs_human_orgids_value').value,concs_human_orgid_checkbox:0+document.getElementById('concs_human_orgid_checkbox').checked, start:0, limit:<%=pageSize%>}});
        }


    </script>
</head>
<body>
</body>
</html>